package com.clubs.coding.Controller;

import com.clubs.coding.Service.AppliCationService;
import com.clubs.coding.Service.Impl.LearningServiceImpl;
import com.clubs.coding.Service.NewsService;
import com.clubs.coding.common.ApiRestResponse;
import com.clubs.coding.model.dao.ApplicationMapper;
import com.clubs.coding.model.dao.LearningMapper;
import com.clubs.coding.model.pojo.Application;
import com.clubs.coding.model.pojo.Learning;
import com.clubs.coding.model.pojo.News;
import com.clubs.coding.model.request.LearningReq;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.catalina.connector.Request;
import org.apache.coyote.Response;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.util.Date;
import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/admin")

public class LearningAdminController {
@Autowired
    LearningServiceImpl learningService;

@Autowired
    LearningMapper learningMapper;
//后台成绩评分
@PostMapping("/evaluate")
    public ApiRestResponse list( Integer pageNum, Integer pageSize, Integer type,Integer id,String report,String evaluate){
    if (id!=null && report!=null && evaluate!=null) {
        Learning learning = new Learning();
        learning.setNullItem(new Date());
        learning.setIsEvaluate(1);
        learning.setReport(report);
        learning.setEvaluate(evaluate);
        learning.setLearningId(id);
        learningMapper.updateByPrimaryKeySelective(learning);
        return ApiRestResponse.success();
    }else{
        PageInfo pageInfo = learningService.evaluate(pageNum, pageSize, type);
        return ApiRestResponse.success(pageInfo);
    }




    }
/**
 * 对学习记录进行评分**/
@PostMapping("/goeva")
public ApiRestResponse goeva(@RequestBody LearningReq learningReq){
    learningReq.setIsEvaluate(1);
    learningReq.setNullItem(new Date());
    Learning learning = new Learning();
    BeanUtils.copyProperties(learningReq,learning);
    learningMapper.updateByPrimaryKeySelective(learning);
return ApiRestResponse.success();
}
}
